/*
 * acm1292.c
 *
 *  Created on: 20 Mar 2010
 *      Author: xuxu
 */

#include<stdio.h>
#include<string.h>

int add(char *num1,char *num2)
{
	int len1,len2,lent,jw;
	char tmp[110];
	int i;
	len1=strlen(num1)-1;
	len2=strlen(num2)-1;
	jw=0;
	lent=0;
	while(len1>=0&&len2>=0)
	{
		tmp[lent++]='0'+(num1[len1]-'0'+num2[len2]-'0'+jw)%10;
		jw=(num1[len1]-'0'+num2[len2]-'0'+jw)/10;
		len1--;
		len2--;
	}
	while(len1>=0)
	{
		tmp[lent++]='0'+(num1[len1]-'0'+jw)%10;
		jw=(num1[len1]-'0'+jw)/10;
		len1--;
	}
	while(len2>=0)
	{
		tmp[lent++]='0'+(num2[len2]-'0'+jw)%10;
		jw=(num2[len2]-'0'+jw)/10;
		len2--;
	}
	if(jw)
		tmp[lent++]='1';
	len1=0;
	for(i=lent-1;i>=0;i--)
		num1[len1++]=tmp[i];
	num1[len1]='\0';
	return len1;
}

int main()
{
	char num1[110],num2[110];
	int len1;
	int n,i;
	scanf("%d\n\n",&n);
	while(n--)
	{
		scanf("%s",num1);
		if(num1[0]=='0')
		{
			printf("0\n");
			continue;
		}
		while(scanf("%s",num2))
		{
			if(num2[0]=='0'&&strlen(num2)==1)
			{
				break;
			}
			len1=add(num1,num2);
		}
		for(i=0;i<len1;i++)
		{
			printf("%c",num1[i]);
		}
		printf("\n");
		if(n)
			printf("\n");
	}
	return 0;
}
